package com.extweb4j.web.controller;

import com.extweb4j.core.anno.AuthAnno;
import com.extweb4j.core.bean.PageInfo;
import com.extweb4j.core.controller.ExtController;
import com.extweb4j.core.model.*;
import com.extweb4j.web.bean.Supplier;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author ZhaoWeinan
 * @date 2018/12/12
 * @description
 */
public class SupplierController extends ExtController{

    /**
     * 列表
     */
    @AuthAnno
    public void list(){
        int page = getParaToInt("page");
        int limit = getParaToInt("limit");
        String keywords = getPara("keywords");

        Page<ExtDepartment> pageData = ExtDepartment.dao.pageDepartmentBy(page,limit,keywords);
        renderJson(pageData);
    }


    /**
     * 审核通过
     */
    @AuthAnno
    public void examinepass(){
        ExtDepartment department = new ExtDepartment();
        department.set("id",getParaToInt("id"));
        department.set("ispassed",1);
        department.update();
        success();
    }

    /**
     * 提交意见
     */
    @AuthAnno
    public void feedback(){
        ExtDepartment department = new ExtDepartment();
        department.set("id",getParaToInt("id"));
        department.set("ispassed",1);
        department.update();
        success();
    }
    /**
     * 审核不通过
     */
    @AuthAnno
    public void examinenopass(){
        success();
    }

    @AuthAnno
    public void get(){
        ExtDepartment department = ExtDepartment.dao.findDepartmentById(getPara("id"));

        if (department.get("FlowRunId") != null && StringUtils.isNotEmpty(department.get("FlowRunId").toString())){
            List<ExtFeedback> extFeedbackList = ExtFeedback.dao.getFeedbackList(department.get("FlowRunId").toString());

            if (extFeedbackList == null){
                department.put("feedbackList",new ArrayList<>());
            }else {
                department.put("feedbackList",extFeedbackList);
            }
        }else {
            department.put("feedbackList",new ArrayList<>());
        }

        renderJson(new Record().set("success",true).set("data",department));
    }
}
